using UnityEngine;

namespace Crosstales.UI.Audio
{
    // [Assembly-CSharp-firstpass.dll].Crosstales.UI.Audio.AudioFilterController
    public class AudioFilterController : MonoBehaviour
    {
        // Fields
        public bool FindAllAudioFiltersOnStart;
        public UnityEngine.AudioReverbFilter[] ReverbFilters;
        public UnityEngine.AudioChorusFilter[] ChorusFilters;
        public UnityEngine.AudioEchoFilter[] EchoFilters;
        public UnityEngine.AudioDistortionFilter[] DistortionFilters;
        public UnityEngine.AudioLowPassFilter[] LowPassFilters;
        public UnityEngine.AudioHighPassFilter[] HighPassFilters;
        public bool ResetAudioFiltersOnStart;
        public bool ChorusFilter;
        public bool EchoFilter;
        public bool DistortionFilter;
        public float DistortionFilterValue;
        public bool LowpassFilter;
        public float LowpassFilterValue;
        public bool HighpassFilter;
        public float HighpassFilterValue;
        public UnityEngine.UI.Dropdown ReverbFilterDropdown;
        public UnityEngine.UI.Text DistortionText;
        public UnityEngine.UI.Text LowpassText;
        public UnityEngine.UI.Text HighpassText;
        private readonly System.Collections.Generic.List<UnityEngine.AudioReverbPreset> reverbPresets;
        private bool initialized;
        
        // Methods
        private void Start()
        {
            var val_15;
            System.Type val_16;
            string val_17;
            var val_18;
            var val_19;
            var val_20;
            var val_21;
            System.Collections.Generic.List<System.Object> val_1 = 536877735;
            if(val_1 == 0)
            {
                    throw new NullReferenceException();
            }
            
            val_15 = 27356920;
            val_1 = new System.Collections.Generic.List<System.Object>();
            val_16 = System.Type.GetTypeFromHandle(handle:  new System.RuntimeTypeHandle() {value = 1073753689});
            val_17 = 0;
            System.Array val_3 = System.Enum.GetValues(enumType:  val_16);
            if(val_3 == null)
            {
                    throw new NullReferenceException();
            }
            
            val_16 = val_3.GetEnumerator();
            label_25:
            val_18 = val_16;
            if((val_16 & 1) == 0)
            {
                goto label_10;
            }
            
            val_19 = val_16;
            if(val_16 == null)
            {
                    throw new NullReferenceException();
            }
            
            val_17 = 536882777;
            val_17 = 0;
            if(536898377 == 0)
            {
                    throw new NullReferenceException();
            }
            
            val_17 = 536882777.ToString();
            536898377 = new UnityEngine.UI.Dropdown.UnityEngine.UI.Dropdown.OptionData(text:  val_17);
            var val_13 = mem[536877763];
            val_13 = val_13 + 1;
            mem[536877763] = val_13;
            if(mem[536877751] == 0)
            {
                    throw new NullReferenceException();
            }
            
            var val_14 = mem[536877759];
            if(val_14 < (mem[536877751] + 24))
            {
                    var val_10 = mem[536877751] + ((mem[536877759]) << 3);
                mem[536877759] = val_14 + 1;
                mem2[0] = 536898377;
                val_17 = 536898377;
            }
            else
            {
                    var val_15 = mem[3221291255] + 192 + 88 + 8;
                val_17 = 536898377;
            }
            
            if(this.reverbPresets == null)
            {
                    throw new NullReferenceException();
            }
            
            val_14 = val_14 + 1;
            mem2[0] = val_14;
            if(val_15 == 0)
            {
                    throw new NullReferenceException();
            }
            
            if(val_14 >= (mem[3221291255] + 192 + 88 + 8 + 24))
            {
                goto label_25;
            }
            
            val_15 = val_15 + (((mem[536877759] + 1)) << 2);
            mem2[0] = val_14 + 1;
            mem2[0] = null;
            goto label_25;
            label_10:
            val_15 = 0;
            label_45:
            if(X0 == false)
            {
                goto label_26;
            }
            
            var val_18 = X0;
            val_16 = X0;
            var val_17 = X0 + 298;
            if(val_17 == 0)
            {
                goto label_27;
            }
            
            var val_16 = X0 + 176;
            val_16 = val_16 + 8;
            label_29:
            if(((X0 + 176 + 8) + -8) == 536887297)
            {
                goto label_28;
            }
            
            val_17 = val_17 - 1;
            val_16 = val_16 + 16;
            if(((X0 + 176 + 8) + -8) != 536887297)
            {
                goto label_29;
            }
            
            label_27:
            val_20 = val_16;
            goto label_30;
            label_28:
            val_18 = val_18 + (((X0 + 176 + 8)) << 4);
            val_20 = val_18 + 312;
            label_30:
            val_17 = mem[((X0 + ((X0 + 176 + 8)) << 4) + 312) + 8];
            val_17 = ((X0 + ((X0 + 176 + 8)) << 4) + 312) + 8;
            label_26:
            if(val_15 == 0)
            {
                    val_16 = this.ReverbFilterDropdown;
                val_17 = 0;
                if(val_16 == val_17)
            {
                    return;
            }
            
                if(this.ReverbFilterDropdown == null)
            {
                    throw new NullReferenceException();
            }
            
                val_17 = 0;
                this.ReverbFilterDropdown.ClearOptions();
                if(this.ReverbFilterDropdown == null)
            {
                    throw new NullReferenceException();
            }
            
                this.ReverbFilterDropdown.AddOptions(options:  val_1);
                return;
            }
            
            if(536887361 != 1)
            {
                goto label_44;
            }
            
            goto label_45;
            label_44:
            label_52:
            if(X0 == false)
            {
                goto label_46;
            }
            
            var val_21 = X0;
            var val_20 = X0 + 298;
            if(val_20 == 0)
            {
                goto label_47;
            }
            
            var val_19 = X0 + 176;
            val_19 = val_19 + 8;
            label_49:
            if(((X0 + 176 + 8) + -8) == 536887297)
            {
                goto label_48;
            }
            
            val_20 = val_20 - 1;
            val_19 = val_19 + 16;
            if(((X0 + 176 + 8) + -8) != 536887297)
            {
                goto label_49;
            }
            
            label_47:
            val_21 = X0;
            goto label_50;
            label_48:
            val_21 = val_21 + (((X0 + 176 + 8)) << 4);
            val_21 = val_21 + 312;
            label_50:
            label_46:
            if(0 != 0)
            {
                goto label_52;
            }
            
            goto label_52;
        }
        private void Update()
        {
            if(this.initialized == true)
            {
                    return;
            }
            
            int val_1 = UnityEngine.Time.frameCount;
            var val_3 = 0;
            val_3 = val_3 + val_1;
            val_3 = (val_3 >> 4) + (val_3 >> 31);
            val_3 = val_1 - (val_3 * 30);
            if(val_3 != 0)
            {
                    return;
            }
            
            this.initialized = true;
            if(this.FindAllAudioFiltersOnStart != false)
            {
                    this.FindAllAudioFilters();
            }
            
            if(this.ResetAudioFiltersOnStart == false)
            {
                    return;
            }
            
            this.ResetAudioFilters();
        }
        public void FindAllAudioFilters()
        {
            Unknown val_2 = UnityEngine.Object.FindObjectsOfType(type:  System.Type.GetTypeFromHandle(handle:  new System.RuntimeTypeHandle() {value = 1073753687}));
            this.ReverbFilters = null;
            Unknown val_4 = UnityEngine.Object.FindObjectsOfType(type:  System.Type.GetTypeFromHandle(handle:  new System.RuntimeTypeHandle() {value = 1073753655}));
            this.ChorusFilters = null;
            Unknown val_6 = UnityEngine.Object.FindObjectsOfType(type:  System.Type.GetTypeFromHandle(handle:  new System.RuntimeTypeHandle() {value = 1073753665}));
            this.EchoFilters = null;
            Unknown val_8 = UnityEngine.Object.FindObjectsOfType(type:  System.Type.GetTypeFromHandle(handle:  new System.RuntimeTypeHandle() {value = 1073753663}));
            this.DistortionFilters = null;
            Unknown val_10 = UnityEngine.Object.FindObjectsOfType(type:  System.Type.GetTypeFromHandle(handle:  new System.RuntimeTypeHandle() {value = 1073753673}));
            this.LowPassFilters = null;
            Unknown val_12 = UnityEngine.Object.FindObjectsOfType(type:  System.Type.GetTypeFromHandle(handle:  new System.RuntimeTypeHandle() {value = 1073753669}));
            this.HighPassFilters = null;
        }
        public void ResetAudioFilters()
        {
            this.ReverbFilterDropdownChanged(index:  0);
            this.ChorusFilterEnabled(isEnabled:  this.ChorusFilter);
            this.EchoFilterEnabled(isEnabled:  this.EchoFilter);
            this.DistortionFilterEnabled(isEnabled:  this.DistortionFilter);
            this.DistortionFilterChanged(value:  this.DistortionFilterValue);
            this.LowPassFilterEnabled(isEnabled:  this.LowpassFilter);
            this.LowPassFilterChanged(value:  this.LowpassFilterValue);
            this.HighPassFilterEnabled(isEnabled:  this.HighpassFilter);
            this.HighPassFilterChanged(value:  this.HighpassFilterValue);
        }
        public void ReverbFilterDropdownChanged(int index)
        {
            if(this.ReverbFilters.Length < 1)
            {
                    return;
            }
            
            var val_3 = 0;
            label_6:
            if(val_3 >= this.ReverbFilters.Length)
            {
                goto label_3;
            }
            
            this.ReverbFilters[val_3].reverbPreset = this.reverbPresets.Item[index];
            val_3 = val_3 + 1;
            if(val_3 < this.ReverbFilters.Length)
            {
                goto label_6;
            }
            
            return;
            label_3:
        }
        public void ChorusFilterEnabled(bool isEnabled)
        {
            if(this.ChorusFilters.Length < 1)
            {
                    return;
            }
            
            var val_3 = 0;
            do
            {
                if(val_3 >= this.ChorusFilters.Length)
            {
                    throw new NullReferenceException();
            }
            
                this.ChorusFilters[val_3].enabled = isEnabled;
                val_3 = val_3 + 1;
            }
            while(val_3 < this.ChorusFilters.Length);
        
        }
        public void EchoFilterEnabled(bool isEnabled)
        {
            if(this.EchoFilters.Length < 1)
            {
                    return;
            }
            
            var val_3 = 0;
            do
            {
                if(val_3 >= this.EchoFilters.Length)
            {
                    throw new NullReferenceException();
            }
            
                this.EchoFilters[val_3].enabled = isEnabled;
                val_3 = val_3 + 1;
            }
            while(val_3 < this.EchoFilters.Length);
        
        }
        public void DistortionFilterEnabled(bool isEnabled)
        {
            if(this.DistortionFilters.Length < 1)
            {
                    return;
            }
            
            var val_3 = 0;
            do
            {
                if(val_3 >= this.DistortionFilters.Length)
            {
                    throw new NullReferenceException();
            }
            
                this.DistortionFilters[val_3].enabled = isEnabled;
                val_3 = val_3 + 1;
            }
            while(val_3 < this.DistortionFilters.Length);
        
        }
        public void DistortionFilterChanged(float value)
        {
            if(this.DistortionFilters.Length >= 1)
            {
                    var val_4 = 0;
                do
            {
                if(val_4 >= this.DistortionFilters.Length)
            {
                    throw new NullReferenceException();
            }
            
                this.DistortionFilters[val_4].distortionLevel = value;
                val_4 = val_4 + 1;
            }
            while(val_4 < this.DistortionFilters.Length);
            
            }
            
            if(this.DistortionText == 0)
            {
                    return;
            }
            
            string val_2 = value.ToString(format:  -1610611397);
        }
        public void LowPassFilterEnabled(bool isEnabled)
        {
            if(this.LowPassFilters.Length < 1)
            {
                    return;
            }
            
            var val_3 = 0;
            do
            {
                if(val_3 >= this.LowPassFilters.Length)
            {
                    throw new NullReferenceException();
            }
            
                this.LowPassFilters[val_3].enabled = isEnabled;
                val_3 = val_3 + 1;
            }
            while(val_3 < this.LowPassFilters.Length);
        
        }
        public void LowPassFilterChanged(float value)
        {
            if(this.LowPassFilters.Length >= 1)
            {
                    var val_4 = 0;
                do
            {
                if(val_4 >= this.LowPassFilters.Length)
            {
                    throw new NullReferenceException();
            }
            
                this.LowPassFilters[val_4].cutoffFrequency = value;
                val_4 = val_4 + 1;
            }
            while(val_4 < this.LowPassFilters.Length);
            
            }
            
            if(this.LowpassText == 0)
            {
                    return;
            }
            
            string val_2 = value.ToString(format:  -1610611407);
        }
        public void HighPassFilterEnabled(bool isEnabled)
        {
            if(this.HighPassFilters.Length < 1)
            {
                    return;
            }
            
            var val_3 = 0;
            do
            {
                if(val_3 >= this.HighPassFilters.Length)
            {
                    throw new NullReferenceException();
            }
            
                this.HighPassFilters[val_3].enabled = isEnabled;
                val_3 = val_3 + 1;
            }
            while(val_3 < this.HighPassFilters.Length);
        
        }
        public void HighPassFilterChanged(float value)
        {
            if(this.HighPassFilters.Length >= 1)
            {
                    var val_4 = 0;
                do
            {
                if(val_4 >= this.HighPassFilters.Length)
            {
                    throw new NullReferenceException();
            }
            
                this.HighPassFilters[val_4].cutoffFrequency = value;
                val_4 = val_4 + 1;
            }
            while(val_4 < this.HighPassFilters.Length);
            
            }
            
            if(this.HighpassText == 0)
            {
                    return;
            }
            
            string val_2 = value.ToString(format:  -1610611407);
        }
        public AudioFilterController()
        {
            this.FindAllAudioFiltersOnStart = true;
            this.ResetAudioFiltersOnStart = true;
            this.DistortionFilterValue = 0.5f;
            this.LowpassFilterValue = 5000f;
            this.HighpassFilterValue = 5000f;
            System.Collections.Generic.List<System.Int32Enum> val_1 = 536903665;
            val_1 = new System.Collections.Generic.List<System.Int32Enum>();
            this.reverbPresets = val_1;
        }
    
    }

}
